package br.com.felipeab.dexter.bean;

import java.io.Serializable;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;

@ManagedBean
@RequestScoped
public class LoginBean implements Serializable {

	private static final long serialVersionUID = 9210712558337085707L;

	public String login() {
		FacesContext context = FacesContext.getCurrentInstance();
		HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();

		try {
			request.login("teste", "123456");
		} catch (ServletException e) {
			e.printStackTrace();
		}

		String result = "/error/expired?faces-redirect=true";

		return "";
	}

	public String logout() {
		String result = "/login?faces-redirect=true";

		FacesContext context = FacesContext.getCurrentInstance();
		HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();
		try {
			request.logout();
		} catch (ServletException ex) {
			result = "/error/loginError?faces-redirect=true";
		}

		return result;
	}
}
